home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / DIKUMUD.ZIP / UTILS.H < prev    next >
Encoding:
Text File  |  1993-05-30  |  8.5 KB  |  292 lines

  1. /*
  2.   SillyMUD Distribution V1.1b             (c) 1993 SillyMUD Developement
  3.  
  4.   See license.doc for distribution terms.   SillyMUD is based on DIKUMUD
  5. */
  6.  
  7. int CAN_SEE(struct char_data *s, struct char_data *o);
  8.  
  9. #if DEBUG
  10.  
  11. #define free(obj) fprintf(stderr, "freeing %d\n", sizeof(*obj));\
  12.               free(obj)
  13.  
  14. #endif
  15.  
  16. #define TRUE  1
  17.  
  18. #define FALSE 0
  19.  
  20. #define LOWER(c) (((c)>='A'  && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
  21.  
  22. #define UPPER(c) (((c)>='a'  && (c) <= 'z') ? ((c)+('A'-'a')) : (c) )
  23.  
  24. #define ISNEWL(ch) ((ch) == '\n' || (ch) == '\r') 
  25.  
  26. #define IS_WEAPON(o) (o->obj_flags.type_flag == ITEM_WEAPON)
  27.  
  28. #define IF_STR(st) ((st) ? (st) : "\0")
  29.  
  30. #define CAP(st)  (*(st) = UPPER(*(st)), st)
  31.  
  32. #define CREATE(result, type, number)  do {\
  33.     if (!((result) = (type *) calloc ((number), sizeof(type))))\
  34.         { perror("malloc failure"); abort(); }\
  35.         } while(0)
  36.  
  37. #define RECREATE(result,type,number) do {\
  38.   if (!((result) = (type *) realloc ((result), sizeof(type) * (number))))\
  39.         { perror("realloc failure"); abort(); } \
  40.         } while(0)
  41.  
  42.  
  43. #define IS_SET(flag,bit)  ((flag) & (bit))
  44.  
  45.  
  46. #define SWITCH(a,b) { (a) ^= (b); \
  47.                       (b) ^= (a); \
  48.                       (a) ^= (b); }
  49.  
  50. #define IS_AFFECTED(ch,skill)  (IS_SET((ch)->specials.affected_by, (skill)))
  51. #define IS_AFFECTED2(ch,skill) (IS_SET((ch)->specials.affected_by2,(skill)))
  52.  
  53. #if 0
  54. #define IS_DARK(room)  (real_roomp(room)->light<=0 && \
  55.     ((IS_SET(real_roomp(room)->room_flags, DARK)) || real_roomp(room)->dark))
  56.  
  57. #define IS_LIGHT(room)  (real_roomp(room)->light>0 || (!IS_SET(real_roomp(room)->room_flags, DARK) || !real_roomp(room)->dark))
  58. #else
  59.  
  60. #define IS_DARK(room) (real_roomp(room)->light <= 0 && \
  61.     ((IS_SET(real_roomp(room)->room_flags, DARK)) ||  \
  62.      IsDarkOutside(real_roomp(room))))
  63.  
  64. #define IS_LIGHT(room) (real_roomp(room)->light>0 || \
  65.      (!IS_SET(real_roomp(room)->room_flags, DARK) || \
  66.       !IsDarkOutside(real_roomp(room))))
  67.  
  68. #endif
  69.  
  70.  
  71.  
  72. #define SET_BIT(var,bit)  ((var) = (var) | (bit))
  73.  
  74. #define REMOVE_BIT(var,bit)  ((var) = (var) & ~(bit) )
  75.  
  76. #define RM_FLAGS(i)  ((real_roomp(i))?real_roomp(i)->room_flags:0)
  77.  
  78. #define GET_LEVEL(ch, i)   ((ch)->player.level[(i)])
  79.  
  80. #define GET_CLASS_TITLE(ch, class, lev)   ((ch)->player.sex ?  \
  81.    (((ch)->player.sex == 1) ? titles[(class)][(lev)].title_m : \
  82.     titles[(class)][(lev)].title_f) : titles[(class)][(lev)].title_m)
  83.  
  84. #define GET_REQ(i) (i<2  ? "Awful" :(i<4  ? "Bad"     :(i<7  ? "Poor"      :\
  85. (i<10 ? "Average" :(i<14 ? "Fair"    :(i<20 ? "Good"    :(i<24 ? "Very good" :\
  86.         "Superb" )))))))
  87.  
  88. #define HSHR(ch) ((ch)->player.sex ?                    \
  89.     (((ch)->player.sex == 1) ? "his" : "her") : "its")
  90.  
  91. #define HSSH(ch) ((ch)->player.sex ?                    \
  92.     (((ch)->player.sex == 1) ? "he" : "she") : "it")
  93.  
  94. #define HMHR(ch) ((ch)->player.sex ?                     \
  95.     (((ch)->player.sex == 1) ? "him" : "her") : "it")    
  96.  
  97. #define ANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "An" : "A")
  98.  
  99. #define SANA(obj) (index("aeiouyAEIOUY", *(obj)->name) ? "an" : "a")
  100.  
  101. #define IS_NPC(ch)  (IS_SET((ch)->specials.act, ACT_ISNPC))
  102.  
  103. #define IS_MOB(ch)  (IS_SET((ch)->specials.act, ACT_ISNPC) && ((ch)->nr >-1))
  104.  
  105. #define GET_POS(ch)     ((ch)->specials.position)
  106.  
  107. #define GET_COND(ch, i) ((ch)->specials.conditions[(i)])
  108.  
  109. #define GET_NAME(ch)    ((ch)->player.name)
  110.  
  111. #define GET_TITLE(ch)   ((ch)->player.title)
  112.  
  113. #define GET_CLASS(ch)   ((ch)->player.class)
  114.  
  115. #define GET_HOME(ch)    ((ch)->player.hometown)
  116.  
  117. #define GET_AGE(ch)     (age(ch).year)
  118.  
  119. #define GET_STR(ch)     ((ch)->tmpabilities.str)
  120.  
  121. #define GET_ADD(ch)     ((ch)->tmpabilities.str_add)
  122.  
  123. #define GET_DEX(ch)     ((ch)->tmpabilities.dex)
  124.  
  125. #define GET_INT(ch)     ((ch)->tmpabilities.intel)
  126.  
  127. #define GET_WIS(ch)     ((ch)->tmpabilities.wis)
  128.  
  129. #define GET_CON(ch)     ((ch)->tmpabilities.con)
  130.  
  131. #define GET_CHR(ch)     ((ch)->tmpabilities.chr)
  132.  
  133.  
  134. #define GET_RSTR(ch)     ((ch)->abilities.str)
  135.  
  136. #define GET_RADD(ch)     ((ch)->abilities.str_add)
  137.  
  138. #define GET_RDEX(ch)     ((ch)->abilities.dex)
  139.  
  140. #define GET_RINT(ch)     ((ch)->abilities.intel)
  141.  
  142. #define GET_RWIS(ch)     ((ch)->abilities.wis)
  143.  
  144. #define GET_RCON(ch)     ((ch)->abilities.con)
  145.  
  146. #define GET_RCHR(ch)     ((ch)->abilities.chr);
  147.  
  148. #define STRENGTH_APPLY_INDEX(ch) \
  149.         ( ((GET_ADD(ch)==0) || (GET_STR(ch) != 18)) ? GET_STR(ch) :\
  150.           (GET_ADD(ch) <= 50) ? 26 :( \
  151.           (GET_ADD(ch) <= 75) ? 27 :( \
  152.           (GET_ADD(ch) <= 90) ? 28 :( \
  153.           (GET_ADD(ch) <= 99) ? 29 :  30 ) ) )                   \
  154.         )
  155.  
  156. #define GET_AC(ch)      ((ch)->points.armor)
  157.  
  158. #define GET_HIT(ch)     ((ch)->points.hit)
  159.  
  160. #define GET_MAX_HIT(ch) (hit_limit(ch))
  161.  
  162. #define GET_MOVE(ch)    ((ch)->points.move)
  163.  
  164. #define GET_MAX_MOVE(ch) (move_limit(ch))
  165.  
  166. #define GET_MANA(ch)    ((ch)->points.mana)
  167.  
  168. #define GET_MAX_MANA(ch) (mana_limit(ch))
  169.  
  170. #define GET_GOLD(ch)    ((ch)->points.gold)
  171.  
  172. #define GET_BANK(ch)    ((ch)->points.bankgold)
  173.  
  174. #define GET_ZONE(ch)    ((ch)->specials.permissions)
  175.  
  176. #define GET_EXP(ch)     ((ch)->points.exp)
  177.  
  178. #define GET_HEIGHT(ch)  ((ch)->player.height)
  179.  
  180. #define GET_WEIGHT(ch)  ((ch)->player.weight)
  181.  
  182. #define GET_SEX(ch)     ((ch)->player.sex)
  183.  
  184. #define GET_RACE(ch)     ((ch)->race)
  185.  
  186. #define GET_HITROLL(ch) ((ch)->points.hitroll)
  187.  
  188. #define GET_DAMROLL(ch) ((ch)->points.damroll)
  189.  
  190. #define AWAKE(ch) (GET_POS(ch) > POSITION_SLEEPING && \
  191.            !IS_AFFECTED(ch, AFF_PARALYSIS) )
  192.  
  193. #if 1
  194. #define WAIT_STATE(ch, cycle)  (((ch)->desc) ? (ch)->desc->wait = ((GetMaxLevel(ch) >= DEMIGOD) ? (0) : (cycle)) : 0)
  195. #endif
  196.  
  197.  
  198.  
  199. /* Object And Carry related macros */
  200.  
  201. #define CAN_SEE_OBJ(sub, obj)                                           \
  202.     (   ( (!IS_NPC(sub)) && (GetMaxLevel(sub)>LOW_IMMORTAL))       ||   \
  203.         ( (( !IS_SET((obj)->obj_flags.extra_flags, ITEM_INVISIBLE) ||   \
  204.          IS_AFFECTED((sub),AFF_DETECT_INVISIBLE) ) &&               \
  205.          !IS_AFFECTED((sub),AFF_BLIND)) &&                          \
  206.              (IS_LIGHT(sub->in_room))))
  207.  
  208. #define GET_ITEM_TYPE(obj) ((obj)->obj_flags.type_flag)
  209.  
  210. #define CAN_WEAR(obj, part) (IS_SET((obj)->obj_flags.wear_flags,part))
  211.  
  212. #define GET_OBJ_WEIGHT(obj) ((obj)->obj_flags.weight)
  213.  
  214. #define CAN_CARRY_W(ch) (str_app[STRENGTH_APPLY_INDEX(ch)].carry_w)
  215.  
  216. #define CAN_CARRY_N(ch) (5+GET_DEX(ch)/2+GetMaxLevel(ch)/2)
  217.  
  218. #define IS_CARRYING_W(ch) ((ch)->specials.carry_weight)
  219.  
  220. #define IS_CARRYING_N(ch) ((ch)->specials.carry_items)
  221.  
  222. #define CAN_CARRY_OBJ(ch,obj)  \
  223.    (((IS_CARRYING_W(ch) + GET_OBJ_WEIGHT(obj)) <= CAN_CARRY_W(ch)) &&   \
  224.     ((IS_CARRYING_N(ch) + 1) <= CAN_CARRY_N(ch)))
  225.  
  226. #define CAN_GET_OBJ(ch, obj)   \
  227.    (CAN_WEAR((obj), ITEM_TAKE) && CAN_CARRY_OBJ((ch),(obj)) &&          \
  228.     CAN_SEE_OBJ((ch),(obj)))
  229.  
  230. #define IS_OBJ_STAT(obj,stat) (IS_SET((obj)->obj_flags.extra_flags,stat))
  231.  
  232.  
  233.  
  234. /* char name/short_desc(for mobs) or someone?  */
  235.  
  236. #define PERS(ch, vict)   (                                          \
  237.     CAN_SEE(vict, ch) ?                                                            \
  238.       (!IS_NPC(ch) ? (ch)->player.name : (ch)->player.short_descr) :    \
  239.       "someone")
  240.  
  241. #define OBJS(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \
  242.     (obj)->short_description  : "something")
  243.  
  244. #define OBJN(obj, vict) (CAN_SEE_OBJ((vict), (obj)) ? \
  245.     fname((obj)->name) : "something")
  246.  
  247. #define OUTSIDE(ch) (!IS_SET(real_roomp((ch)->in_room)->room_flags,INDOORS))
  248.  
  249. #define IS_IMMORTAL(ch) (!IS_NPC(ch)&&(GetMaxLevel(ch)>=LOW_IMMORTAL))
  250.  
  251. #define IS_POLICE(ch) ((mob_index[ch->nr].virtual == 3060) || \
  252.                        (mob_index[ch->nr].virtual == 3069) || \
  253.                        (mob_index[ch->nr].virtual == 3067))
  254.  
  255. #define IS_CORPSE(obj) (GET_ITEM_TYPE((obj))==ITEM_CONTAINER && \
  256.             (obj)->obj_flags.value[3] && \
  257.             isname("corpse", (obj)->name))
  258.  
  259. #define EXIT(ch, door)  (real_roomp((ch)->in_room)->dir_option[door])
  260.  
  261. int exit_ok(struct room_direction_data *, struct room_data **);
  262.  
  263. #define CAN_GO(ch, door) (EXIT(ch,door)&&real_roomp(EXIT(ch,door)->to_room) \
  264.                           && !IS_SET(EXIT(ch, door)->exit_info, EX_CLOSED))
  265.  
  266. #define CAN_GO_HUMAN(ch, door) (EXIT(ch,door) && \
  267.               real_roomp(EXIT(ch,door)->to_room) \
  268.                           && !IS_SET(EXIT(ch, door)->exit_info, EX_LOCKED))
  269.  
  270. #define GET_ALIGNMENT(ch) ((ch)->specials.alignment)
  271.  
  272. #define IS_GOOD(ch)    (GET_ALIGNMENT(ch) >= 350)
  273. #define IS_EVIL(ch)    (GET_ALIGNMENT(ch) <= -350)
  274. #define IS_NEUTRAL(ch) (!IS_GOOD(ch) && !IS_EVIL(ch))
  275.  
  276. #define ITEM_TYPE(obj)  ((int)(obj)->obj_flags.type_flag)
  277.  
  278. #define IS_PC(ch) (!IS_NPC((ch)) || IS_SET((ch)->specials.act, ACT_POLYSELF))
  279.  
  280.  
  281. #define GET_AVE_LEVEL(ch) (GetMaxLevel(ch)+(GetSecMaxLev(ch)/2)+\
  282.       (GetThirdMaxLev(ch)/3))
  283.  
  284. #define GET_ALIAS(ch, num) ((ch)->specials.A_list->com[(num)])
  285.  
  286. #define MOUNTED(ch) ((ch)->specials.mounted_on)
  287. #define RIDDEN(ch) ((ch)->specials.ridden_by)
  288.  
  289. #if 0
  290. #define isdigit(ch) (ch >= '0' && ch <= '9')
  291. #endif
  292.